import Message from './Message.vue';
import Vue from 'vue';

// 获取Message组件的构造函数
// 通过vue.extend()新建一个子类MessageConstructor
// Message是对应的Message的模板
const MessageConstructor = Vue.extend(Message);

const serve = (message)=>{
    // 创建message实例
    let messageInstance = new MessageConstructor();
    // 将组件挂载到指定的元素
    messageInstance.$mount(document.createElement('div'));
    // 将组件挂载的元素添加到body元素下
    document.body.appendChild(messageInstance.$el);

    messageInstance.message = message;
    messageInstance.visible = true;
    Vue.nextTick(()=>{
        setTimeout(() => {
            messageInstance.visible = false;
        },3000);
    })
}

export default serve;